﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.IO;

/// <summary>
/// Main contract call
/// </summary>
[ServiceContract()]
public interface ITransferFiles
{
    /// <summary>
    /// Download file contract, using DownloadRequest Object
    /// </summary>
    /// <param name="request"></param>
    /// <returns>RemoteFileInfo</returns>
    [OperationContract]
    RemoteFileInfo DownloadFile(DownloadRequest request);


    /// <summary>
    /// Upload file contract. uses RemoteFileInfo object. no return
    /// </summary>
    /// <param name="request"></param>
    [OperationContract]
    void UploadFile(RemoteFileInfo request);

    

    /// <summary>
    /// Used to authenticate user against DB.
    /// </summary>
    /// <param name="username"></param>
    /// <param name="pwd"></param>
    /// <returns>GroupID or 99 if not authenticated</returns>
    [OperationContract]
    int AuthUser(string username, string pwd);


    [OperationContract]
    List<FileInformation> GetList(string username, string pwd, int group);

    [OperationContract]
    List<HelperClass> GetGroups();

    [OperationContract]
    int ChangePassword(string username, string pwd, string updateUser, string newPwd);

    [OperationContract]
    List<HelperClass> GetUsers(string username, string pwd, string groupName);

    [OperationContract]
    int DeleteUser(string username, string pwd, string delUserName);

    [OperationContract]
    int AddUser(HelperClass user, HelperClass newUser);

    [OperationContract]
    int AddGroup(string username, string pwd, string groupName);

    [OperationContract]
    int DelGroup(string username, string pwd, string groupName);

    [OperationContract]
    int DeleteFile(string username, string pwd, string filepath);

}

/// <summary>
/// DownloadRequest Object used for requesting file downloads
/// </summary>
[MessageContract]
public class DownloadRequest
{
    //param passed to request filestream return
    [MessageHeader(MustUnderstand = true)]
    public string UserName { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string Password { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string FileName { get; set; }    

    [MessageHeader(MustUnderstand = true)]
    public string FilePart { get; set; }
    
}

/// <summary>
/// RemoteFileInfo Object used to pass information about files
/// </summary>

[MessageContract]
public class RemoteFileInfo 
{
    //additional param passed with file stream
    [MessageHeader(MustUnderstand = true)]
    public string UserName {get; set;}

    [MessageHeader(MustUnderstand = true)]
    public string Password { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string Group { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public string FileName { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public int FileStart { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public long FileSize { get; set; }

    [MessageHeader(MustUnderstand = true)]
    public int NumParts { get; set; }

    //MessageBody can only contain Stream
    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream;

      
}




